package com.loriot.common.living_people_lcci_;

/**
 * @Title: pointsThatIntersectWithCars_2848
 * @Package: com.loriot.common
 * @Description:
 * @Author: zzy boy
 * @Date: 2025/10/21 10:36
 * @Version: 0.0.1-alpha
 */

public class Main {
    class Solution1 {
        public boolean isCovered(int[][] ranges, int left, int right) {
            int size = right-left+1;
            int[] helper = new int[size+1];


            for(int i=0;i<ranges.length;i++){
                int[] item = ranges[i];
                // 不相交
                if(item[1]<left)continue;
                if(item[0]>right)continue;
                // 左侧超出目标区间
                if(item[0]<=left){
                    helper[0]++;
                }else{
                    helper[item[0]-left]++;
                }
                // 右侧超出目标区间
                if(item[1]>=right){
                    // 最后一位
                    helper[right-left+1]--;
                }else{
                    helper[item[1]-left+1]--;
                }
            }
            int difference = 0;
            for(int i=0;i<size;i++){
                difference+=helper[i];
                if(difference<=0)return false;
            }
            return true;


        }
    }

    class Solution2 {
        public boolean isCovered(int[][] ranges, int left, int right) {
            // 1 <= ranges.length <= 50
            // 1 <= starti <= endi <= 50
            // 1 <= left <= right <= 50
            int[] helper = new int[51];
            for(int i=0;i<ranges.length;i++){
                int[] item = ranges[i];
                helper[item[0]-1]++;
                helper[item[1]]--;
            }
            int difference = 0;
            for(int i=0;i<helper.length;i++){
                difference+=helper[i];
                if(i>=left-1&&i<=right-1&&difference <=0)return false;
            }
            return true;
        }
    }
}
